const tradeList = [
  {
    id:1,
    itemID:1,
    from:"1@1.com",
    to:"",
    type:1,
    price:0,
    createdAt:new Date()
  },
  {
    id:2,
    itemID:1,
    from:"1@1.com",
    to:"2@2.com",
    type:2,
    price:0,
    createdAt:new Date()
  },
  {
    id:3,
    itemID:1,
    from:"1@1.com",
    to:"2@2.com",
    type:3,
    price:0,
    createdAt:new Date()
  },
  {
    id:4,
    itemID:2,
    from:"1@1.com",
    to:"2@2.com",
    type:4,
    price:0,
    createdAt:new Date()
  },
  {
    id:5,
    itemID:2,
    from:"1@1.com",
    to:"2@2.com",
    type:5,
    price:0,
    createdAt:new Date()
  },
]

const tradeTypeList = [
  {
    value: 1,
    label: '创建',
  },
  {
    value: 2,
    label: '转让',
  },
  {
    value: 3,
    label: '交易',
  },
  {
    value: 4,
    label: '出售',
  },
  {
    value: 5,
    label: '拍卖',
  },
  {
    value: 6,
    label: '授权',
  },
  {
    value: 7,
    label: '报价',
  },
]

const getTradeByItemID = (itemID)=>{
  const resultList = [];
  for (let i=0;i<tradeList.length;i++){
    if(itemID === tradeList[i].itemID){
      resultList.push(tradeList[i])
    }
  }
  return resultList
}

const getTradeByType = (type)=>{
  const resultList = [];
  for (let i=0;i<tradeList.length;i++){
    if(type === tradeList[i].type){
      resultList.push(tradeList[i])
    }
  }
  return resultList
}

export default {
  'GET /api/getTradeTypeList': (req,res)=>{
    res.send({
      'status':'ok',
      'tradeTypeList':tradeTypeList,
    });
  },
  'GET /api/searchTradeList': (req,res)=>{
    const { itemID,type } = req.query;
    console.log(itemID)
    console.log(type)
    const tradeList = getTradeByItemID(parseInt(itemID))
    if (type===undefined){
      res.send({
        'success':true,
        'data':tradeList,
        'total':tradeList.length,
      });
      return
    }
    const resultList = getTradeByType(type)
    res.send({
      'success':true,
      'data':resultList,
      'total':resultList.length,
    });
  },
};
